#!/bin/sh

#
# This is a semi-automated test suite for SLglade.  It should be run *after*
# the module is installed.  If glade-module.so was installed to a
# non-standard location, you will need to configure your environment properly
# (e.g. add the module's location to SLANG_MODULE_PATH) before running the
# tests.
#


do_msg() {
  echo "$*" >&2
}

SLSH=`which slsh`

if [ -z "$SLSH" -o ! -x "$SLSH" ]; then
  do_msg "ERROR: cannot find slsh"
  exit 1
fi

testnum=1

do_test() {
  do_msg ""
  do_msg ""
  do_msg "##"
  do_msg "## Test $testnum"
  do_msg "##"
  do_msg ""

  do_msg "$*"

  testnum=`expr $testnum + 1`
}

do_wait() {
  do_msg ""
  do_msg "Press ENTER to continue"
  read newline
}

startdir=`pwd`


#
# Basic tests
#

cd ../examples

do_test "Check for \"gtk module has not been loaded\" error (except on
Mac OS X and other Darwin-based systems, which should give an
\"Undefined symbols\" error)
"
echo 'import("glade");' | $SLSH
do_wait

do_test "Check for correct version number and version string
"
echo 'import("gtk"); import("glade"); message(_glade_module_version_string);
message(string(_glade_module_version));' | $SLSH
do_wait

do_test "Press the button"
$SLSH basic.sl
do_test "Close via window manager"
$SLSH basic.sl

do_test "Press the button"
$SLSH buffer_basic.sl
do_test "Close via window manager"
$SLSH buffer_basic.sl

do_test "Compare output against expected output, then press button

** Expected output **

All widgets:
  button1
  window1
Widgets matching prefix \"\":
  button1
  window1
Widgets matching prefix \"win\":
  window1
No widgets matching prefix \"winy\"

** Actual output **
"

$SLSH get_widget.sl

do_test "Close via window manager (output can be ignored)
"

$SLSH get_widget.sl

do_test "Press button, then compare output against expected output

** Expected output **

window1 was passed to my_destroy()
You destroyed me!

** Actual output **
"

$SLSH signal_connect.sl
do_wait

do_test "Close via window manager, then compare output against expected output

** Expected output **

window1 was passed to my_destroy()
You called my_destroy()!

** Actual output **
"

$SLSH signal_connect.sl
do_wait

do_test "Check for \"MainWindow successfully NOT created\" message, then press OK
"
$SLSH root_widget.sl

do_test "Play with the widgets, then close"
$SLSH example.sl

do_test "Play with the widgets, then close"
$SLSH texteditor.sl

cd $startdir

do_test "XML path tests
"
$SLSH path_test.sl
do_wait

do_test "Miscellaneous function tests
"
$SLSH function_test.sl


#
# Package tests
#

do_test "Package tests
"
$SLSH package_test.sl
do_wait


#
# ISIS tests
#

ISIS=`which isis`

if [ -n "$ISIS" -a -x "$ISIS" ]; then
  do_test "ISIS tests
"
  $ISIS --batch isis_test.sl
  do_wait
fi


do_msg "
All tests complete!
"
exit 0

